package com.sjz.han.industry.adapters;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.sjz.han.industry.R;
import com.sjz.han.industry.activites.ProductJsActivity;
import com.sjz.han.industry.entities.GongLueEntity;
import com.sjz.han.industry.entities.HomeEntity;
import com.sjz.han.industry.internetmanage.ReqestUrl;
import com.sjz.han.industry.utils.PicUtils;

import java.util.ArrayList;
import java.util.List;


/**
 *图文介绍适配器
 */
public class GonLueAdapter extends RecyclerView.Adapter<GonLueAdapter.ViewHolder> {
    private Context context;
    public List<GongLueEntity.GongLueData.GonglueBean> datas=new ArrayList<>();
    public GonLueAdapter(Context context) {
        this.context=context;
    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    public void setAdapterDatas(List<GongLueEntity.GongLueData.GonglueBean> datas){
        this.datas=datas;
        notifyDataSetChanged();
    }
    @Override
    public GonLueAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new GonLueAdapter.ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_twjs_item, parent, false));
    }

    @Override
    public void onBindViewHolder(GonLueAdapter.ViewHolder holder, final int position) {
                    PicUtils.showImgRounded(context, holder.home_prodcut_img, ReqestUrl.BASE+datas.get(position).imgUrl);
       holder.home_prodcutname_tv.setText(datas.get(position).name);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                context.startActivity(new Intent(context, ProductJsActivity.class).putExtra("imagId",datas.get(position).id));
            }
        });
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        public ImageView home_prodcut_img;
        public TextView home_prodcutname_tv;
        public ViewHolder(View itemView) {
            super(itemView);
            home_prodcut_img=(ImageView)itemView.findViewById(R.id.home_prodcut_img);
            home_prodcutname_tv=(TextView)itemView.findViewById(R.id.home_prodcutname_tv);
        }

    }
}